package com.management.department.teacherinfosystem.Entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "textbooks")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Textbook {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @JsonIgnore
    private User user;

    private String title;
    private String isbn;
    private String publisher;

    @Column(name = "publish_date")
    private LocalDate publishDate;

    @Column(name = "word_count")
    private Integer wordCount;

    @Column(name = "editor_role")
    private String editorRole;

    @Column(name = "in_campus_rank")
    private Integer inCampusRank;

    @Column(name = "textbook_type")
    private String textbookType;

    private String level;

    @Column(name = "reprint_info")
    private String reprintInfo;

    @Column(length = 16)
    private String status = "PENDING";

    @Column(name = "review_opinion", columnDefinition = "TEXT")
    private String reviewOpinion;

    @Column(name = "reviewer_id")
    private Long reviewerId;

    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    @Column(name = "created_at")
    private LocalDateTime createdAt;

    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    @PrePersist
    public void prePersist() {
        LocalDateTime now = LocalDateTime.now();
        createdAt = now;
        updatedAt = now;
    }

    @PreUpdate
    public void preUpdate() {
        updatedAt = LocalDateTime.now();
    }
} 